using System;
using System.Collections.Generic;
using System.Data;
using System.Data.Entity;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using trytotest.Models;

namespace trytotest.Controllers
{   
    public class ArticlesController : Controller
    {
        private trytotestContext context = new trytotestContext();

        //
        // GET: /Articles/
        public ViewResult List()
        {
           // List<Articles> l = context.Articles.ToList();
            TryToTestEntitiesArticles a = new TryToTestEntitiesArticles();
            List<Articles> l = new List<Articles>();
            Articles l1 = new Articles { Title = "11", Abstract = "12121212", Url = "111", Tags = "1212,1212" };
            l.Add(l1);
            l = a.Articles.ToList();
            
            return View(l);
        }

        //
        // GET: /Articles/Details/5

        public ViewResult Details(int id)
        {
           Models.Articles articles = context.Articles.Single(x => x.ArticlesID == id);
            return View(articles);
        }

        //
        // GET: /Articles/Create

        public ActionResult Create()
        {
            return View();
        } 

        //
        // POST: /Articles/Create

        [HttpPost]
        public ActionResult Create(Models.Articles articles)
        {
            if (ModelState.IsValid)
            {
                context.Articles.Add(articles);
                context.SaveChanges();
                return RedirectToAction("List");  
            }

            return View(articles);
        }
        
        //
        // GET: /Articles/Edit/5
 
        public ActionResult Edit(int id)
        {
            Models.Articles articles = context.Articles.Single(x => x.ArticlesID == id);
            return View(articles);
        }

        //
        // POST: /Articles/Edit/5

        [HttpPost]
        public ActionResult Edit(Articles articles)
        {
            if (ModelState.IsValid)
            {
                context.Entry(articles).State = EntityState.Modified;
                context.SaveChanges();
                return RedirectToAction("List");
            }
            return View(articles);
        }

        //
        // GET: /Articles/Delete/5
 
        public ActionResult Delete(int id)
        {
            Models.Articles articles = context.Articles.Single(x => x.ArticlesID == id);
            return View(articles);
        }

        //
        // POST: /Articles/Delete/5

        [HttpPost, ActionName("Delete")]
        public ActionResult DeleteConfirmed(int id)
        {
            Models.Articles articles = context.Articles.Single(x => x.ArticlesID == id);
            context.Articles.Remove(articles);
            context.SaveChanges();
            return RedirectToAction("List");
        }

        protected override void Dispose(bool disposing)
        {
            if (disposing) {
                context.Dispose();
            }
            base.Dispose(disposing);
        }
    }
}